#include "screenrecoder.h"
#include <chrono>
using namespace std::chrono;

ScreenRecoder::ScreenRecoder(QObject *parent) : QThread{parent} {
  connect(this, &QThread::started, this, &ScreenRecoder::onStarted);
  connect(this, &QThread::finished, this, &ScreenRecoder::onFinished);
}

void ScreenRecoder::saveImage(std::shared_ptr<QImage> img) { ++m_iFpsCount; }

void ScreenRecoder::run() { exec(); }

void ScreenRecoder::timerEvent(QTimerEvent *event) {
  if (event->timerId() == timer_showfps) {
    print_fps();
  }
}

void ScreenRecoder::print_fps() {
  qDebug() << "grab fps:" << m_iFpsCount;
  m_iFpsCount = 0;
}

void ScreenRecoder::onStarted() { timer_showfps = startTimer(1s); }

void ScreenRecoder::onFinished() { killTimer(timer_showfps); }
